//
//  TTScreenItemsViewCell.m
//  TaoTuo
//
//  Created by LG on 2020/11/18.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "LLScreenItemsViewCell.h"
#import "LLScreenItemView.h"

@interface LLScreenItemsViewCell ()

/// 标题
@property (nonatomic, strong) UILabel *titleLabel;
/// 选择item
@property (nonatomic, strong) LLScreenItemView *itemView;
/// 案例图片
@property (nonatomic, strong) UIImageView *demoImgView;
/// 提示文案
@property (nonatomic, strong) UIButton *hintBtn;

@end

@implementation LLScreenItemsViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupSubviews];
        
    }
    return self;
}

- (void)setupSubviews
{
    _titleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(333333) fontSize:14];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.left.mas_equalTo(15);
    }];
    
    _itemView = [[LLScreenItemView alloc] init];
    [self addSubview:_itemView];
    [self.itemView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(15);
        make.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(30);
    }];
    
    _demoImgView = [[UIImageView alloc] init];
    [self addSubview:_demoImgView];
    [_demoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.itemView);
        make.right.equalTo(self.contentView.mas_right).offset(-20);
        make.width.mas_equalTo(143);
        make.height.mas_equalTo(54);
    }];
    
    _hintBtn = [UIButton createButtonWithTitle:@"" titleColor:UIColorHex(#FC832A) titleFont:[UIFont systemFontOfSize:12] backgroundColor:nil target:nil action:nil];
    _hintBtn.enabled = NO;
    [self addSubview:_hintBtn];
    [_hintBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.itemView.mas_bottom).offset(5);
        make.left.equalTo(self.titleLabel);
    }];
    
}

- (void)setModel:(LLScreenSectionModel *)model
{
    _model = model;
    
    self.titleLabel.text = model.sectionTitle;
    
    self.itemView.model = model;
    
    if (model.rightImageName.length > 0) {
        if ([model.rightImageName hasPrefix:@"http"]) {
            NSString *urlStr = [model.rightImageName stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [self.demoImgView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:nil options:SDWebImageRetryFailed];
        } else {
            self.demoImgView.image = [UIImage imageNamed:model.rightImageName];
        }
    }
    self.demoImgView.hidden = model.rightImageName.length == 0;
    
    [self.hintBtn setTitle:model.hintString forState:UIControlStateDisabled];
    [self.hintBtn setImage:[UIImage imageNamed:model.hintImageName] forState:UIControlStateDisabled];
    [self.hintBtn setTitleColor:model.hintTextColor forState:UIControlStateDisabled];
    self.hintBtn.hidden = model.hintString.length == 0;
    
}




@end
